package com.neuedu.security.controller;

import com.github.pagehelper.PageInfo;
import com.neuedu.security.model.Article;
import com.neuedu.security.model.Category;
import com.neuedu.security.model.RespBean;
import com.neuedu.security.service.ArticleService;
import com.neuedu.security.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @Autowired
    CategoryService categoryService;

    @PostMapping("/addArticle")
    public RespBean addArticle(@RequestBody Article article) {
        return articleService.addArticle(article);
    }

    @PutMapping("/updateArticle")
    public RespBean updateArticle(@RequestBody Article article) {
        return articleService.updateArticle(article);
    }

    @GetMapping("/getCategory")
    public List<Category> getCategory(String keyWords) {
        return categoryService.getCategory(keyWords);
    }

    @GetMapping("/getArticle/{id}")
    public RespBean getArticle(@PathVariable int id) {
        return articleService.getArticle(id);
    }

    @GetMapping("/getArticlesByStatus")
    public PageInfo getArticlesByStatus(int status, String titleKeyWords, @RequestParam(value = "pageNumber", defaultValue = "1") int pageNumber, @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        return articleService.getArticlesByStatus(status, titleKeyWords, pageNumber, pageSize);
    }

    @GetMapping("/judgeAdminOrUser")
    public RespBean judgeAdminOrUser(int uid) {
        return articleService.judgeAdminOrUser(uid);
    }

    @GetMapping("/getArticleContent")
    public Article getArticleContent(int id) {
        return articleService.getArticleContent(id);
    }

    @PutMapping("/recoverArticle")
    public RespBean recoverArticle(@RequestBody Article article) {
        return articleService.recoverArticle(article);
    }

    @DeleteMapping("delArticleById/{id}")
    public RespBean delArticleById(@PathVariable int id){
        return articleService.delArticleById(id);
    }

    @GetMapping("/getArticleDetailsById")
    public Article getArticleDetailsById(int id){
        return articleService.getArticleDetailsById(id);
    }
}
